package com.chiga.interceptor;

import java.util.Set;

import org.apache.struts2.json.JSONUtil;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

public class FilterActionInterceptor extends AbstractInterceptor {

	private static final long serialVersionUID = -782473784435483353L;
	
	private Set<String> include;
	
	@Override
	public String intercept(ActionInvocation ai) throws Exception {
		if (include == null) return ai.invoke();
		String action = ai.getProxy().getConfig().getClassName();
		
		if (!include.contains(action)) {
			throw new NoClassDefFoundError(action);
		}
		
		return ai.invoke();
	}

	public void setInclude(String param) {
		include = JSONUtil.asSet(param);
	}
}
